import {
  find,
  cancel
} from '../../../../api/askfor';
const util = require('../../../../utils/util.js')
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    detailsForm: null,
    orderLog: [],
    files:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.data.id = options.id
  },
  onShow:function(){
    this.findClick()
  },
  logisticsClick() {
    wx.navigateTo({
      url: '/pages/order/jumpPage/order/logistics?id=' + this.data.id
    })
  },
  findClick() {
    var _this = this
    find(this.data.id).then(
      res => {
        if (res.type == 'success') {
          console.log(res)
          _this.data.detailsForm = res.data.askfor
          _this.data.detailsForm.createDate = util.datetimeFormat(_this.data.detailsForm.createDate)
          _this.data.orderLog = res.data.askforLog
          if (!util.isNull(_this.data.orderLog)) {
            _this.data.orderLog.forEach(function(item) {
              item.createDate = util.datetimeFormat(item.createDate)
            })
          }
          _this.data.detailsForm.itemList.forEach(function(item) {
            item.thumbnail = util.thumbnail(item.thumbnail, 120, 120)
          })
          _this.data.files = res.data.files
          _this.setData({
            detailsForm: _this.data.detailsForm,
            orderLog: _this.data.orderLog,
            files: _this.data.files
          })
        }
      }
    ).catch(error => {
      console.log(error)
    })
  },
  cancelClick() {
    var _this = this
    wx.showModal({
      title: '提示',
      content: '是否确认取消',
      success(res) {
        if (res.confirm) {
          cancel(_this.data.id).then(
            res => {
              if (res.type == 'success') {
                console.log(res)
                wx.showToast({
                  title: res.content,
                })
                wx.navigateBack({
                  delta: 1
                })
              }
            }
          ).catch(error => {
            console.log(error)
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  toViewClick(){
    wx.navigateTo({
      url: '/pages/order/jumpPage/order/logisticsList?id=' + this.data.id
    })
  }
})